<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>控制器中使用filter过滤器服务 </title>
		<script src="../org/angular.min.js" ></script>
	</head>
	<body>
		<div ng-app = "hd" ng-controller = "ctrl">
			<!--{{data}}
		    </br>
			<input type="submit" ng-click='orderBy()' value="重新排序" />-->
			
			<table border="1" width="660px">
				<tr>
					<td ng-click="orderBy('id')">编号
					    <span ng-if="!status.id">升序</span>
					    <span ng-if="status.id">降序</span>
					</td>
					<td ng-click="orderBy('age')">年龄
					    <span ng-if="!status.age">升序</span>
					    <span ng-if="status.age">降序</span>
					</td>
					<td ng-click="orderBy('url')">链接
					    <span ng-if="!status.url">升序</span>
					    <span ng-if="status.url">降序</span>
					</td>
				</tr>
				<tr ng-repeat='v in data'>
					<td>{{v.id}}</td>
					<td>{{v.age}}</td>
					<td>{{v.url}}</td>
				</tr>
			</table>
		</div> 
		<script>
			var m = angular.module('hd',[]);
			m.controller('ctrl',['$scope','$filter',function($scope,$filter){
				$scope.data = [{id:1,age:100,url:"www.scb"},
				{id:2,age:200,url:"www.baidu"},
				{id:3,age:300,url:"www.jd.com"}
				];
//				$scope.orderBy = function(){
//					$scope.data = $filter('orderBy')($scope.data,'id',true);
//				}

//              arguments.callee()实现
//              $scope.orderBy = function(filed){
//             	    if(arguments.callee[filed] == undefined){
//             	    	arguments.callee[filed] = false;
//             	    }
//             	    arguments.callee[filed] = !arguments.callee[filed]
//             	    $scope.data = $filter('orderBy')($scope.data,filed,arguments.callee[filed]);
//              }
                
//              $scope.status实现
                $scope.status = {id: false, age: false, url: false};
                $scope.orderBy = function(filed){
               	    $scope.status[filed] = !$scope.status[filed];
               	    $scope.data = $filter('orderBy')($scope.data,filed,$scope.status[filed]);
                }
			}]);
		</script>
	</body>
</html>
